/**
 * Created by commy on 2015/4/30.
 */
var qs = require('querystring');
var redis = require('./redis');
var appSession = function(req,res,next){
    var sessionid = req.header('sessionid') || qs.parse(req.url.slice(req.url.indexOf('?')+1)).sessionid;
    if(sessionid){
        console.log(sessionid);
        redis.hget('sessionid',sessionid).then(function(result){
            console.log(result);
            if(result){
                req.userid = result;
                next();
            }else{
              res.status(503).json({state:'error',error_msg:'login first please'});
            }
        },function(err){
            next(err);
        });
    }
}
module.exports = appSession;